<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use App\Models\Product;

class CreateProductsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('category_id')->comment('分类ID');
            $table->string('type')->default(Product::TYPE_SINGLE)->comment('商品类型');
            $table->string('title')->nullable()->comment('商品标题');
            $table->string('image')->comment('商品图片');
            $table->string('product_name')->comment('商品 product_name');
            $table->string('brand')->comment('商品 brand');
            $table->string('packaging_information')->comment('商品 packaging_information');
            $table->string('shelf_life')->comment('商品 shelf_life');
            $table->string('ingredient')->comment('商品 ingredient');
            $table->string('place_of_origin')->comment('商品 place_of_origin');
            $table->string('barcode_image')->nullable()->comment('条码图片');
            $table->timestamps();

            $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        });
        \DB::statement("ALTER TABLE `products` comment'商品'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('products');
    }
}
